package com.wxw.springcloud.seata.controller;

import com.wxw.springcloud.seata.dao.TradeMapper;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wxw
 * @data 2021/11/14 20 :32
 * @description
 */
@RestController
@RequestMapping("/trade")
@Slf4j
public class TradeController {
    @Resource
    private TradeMapper tradeMapper;

    @PostMapping("ir")
    @Transactional
    public  void  InventoryReduction(@RequestParam("id") Integer id){
        log.info("开始减少库存");
        tradeMapper.reduceStockById(id);
        log.info("库存减少完成");
        //throw new RuntimeException();

    }
}
